package com.example.jvm;

import java.util.Arrays;

/**
 * Created by zengliang on 17/5/29.
 */

public class ClassLoaderTest {
    public static void main(String[] args) throws Exception {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        System.out.println(classLoader);
        System.out.println(classLoader.getParent());
        System.out.println(classLoader.getParent().getParent());

        //sun.misc.Launcher$AppClassLoader@1b6d3586
        //sun.misc.Launcher$ExtClassLoader@7f31245a
        //null
        //Bootstrap Loader是采用C语言实现的，找不到一个确定返回父Loader的形式，就返回null了。


        Class.forName("com.example.Interviews");
//        Class.forName("com.example.jvm.ClassLoaderTest.LoadClass");


//        String printMsg = MessageFormat.format("print:{0},{1}", 25, "abcd");
        String msg = "print:{},{},{}";
        Object[] objects = {25,"abcd", 345, "dklf"};
        System.out.println(getMsg(msg, Arrays.copyOf(objects, objects.length - 1)));
        System.out.println(msg);
        System.out.println(change(msg));
        System.out.println(String.format(change(msg),"abcd", "dklf"));
    }


    public static class LoaderClass {
        static {
            System.out.println("LoaderClass,静态代码块被执行了");
        }
    }

    public static String getMsg(String msg, Object... objects){
        for (Object object : objects) {
            msg = msg.replaceFirst("\\{\\}", object.toString());
            System.out.println(msg);
        }
        return msg;
    }

    public static String change(String msg){
        return msg.replaceAll("\\{\\}", "%s");
    }



}

